﻿using System;
using System.ComponentModel;

namespace RiskMan.DataClass.Models.Sterling
{
    public class SterlingPositonModel : INotifyPropertyChanged
    {

        #region private

        private string _sym;
        private string _acct;
        private string _instrument;

        private long _openingPosition;
        private long _sharesBot;
        private long _sharesSld;
        private long _sharesSldLong;
        private long _sharesSldShort;
        private long _ticketsBot;
        private long _ticketsSld;
        private long _ticketsSldLong;
        private long _ticketsSldShort;

        private double _closePrice;
        private double _dollarsBot;
        private double _dollarsSld;
        private double _dollarsSldLong;
        private double _dollarsSldShort;
        private double _positionCost;
        private double _premiumMultiplier;
        private double _real;

        private long _sharesPerContract;
        private long _nPremiumMultiplier;

        private double _last;
        private double _msgSnapShot;

        #endregion

        #region public
        
        /// <summary>
        /// Symbol
        /// </summary>
        public string Sym
        {
            get { return _sym; }
            set
            {
                if (_sym != value)
                {
                    _sym = value;
                    RaisePropertyChanged("Sym");
                }
            }
        }
        
        /// <summary>
        /// Trading account
        /// </summary>
        public string Acct
        {
            get { return _acct; }
            set
            {
                if (_acct != value)
                {
                    _acct = value;
                    RaisePropertyChanged("Acct");
                }
            }
        }
        
        /// <summary>
        /// Position instrument
        /// </summary>
        public string Instrument
        {
            get { return _instrument; }
            set
            {
                if (_instrument != value)
                {
                    _instrument = value;
                    RaisePropertyChanged("Instrument");
                }
            }
        }



        
        /// <summary>
        /// The position in the account to start the day.
        /// </summary>
        public long OpeningPosition
        {
            get { return _openingPosition; }
            set
            {
                if (_openingPosition != value)
                {
                    _openingPosition = value;
                    RaisePropertyChanged("OpeningPosition");
                }
            }
        }
        
        /// <summary>
        /// Number of Share purchased
        /// </summary>
        public long SharesBot
        {
            get { return _sharesBot; }
            set
            {
                if (_sharesBot != value)
                {
                    _sharesBot = value;
                    RaisePropertyChanged("SharesBot");
                }
            }
        }
        
        /// <summary>
        /// Number of Shares Sold. (nSharesSldLong+ nSharesSldShort)
        /// </summary>
        public long SharesSld
        {
            get { return _sharesSld; }
            set
            {
                if (_sharesSld != value)
                {
                    _sharesSld = value;
                    RaisePropertyChanged("SharesSld");
                }
            }
        }
        
        /// <summary>
        /// Number of Shares sold long this is a component of nSharesSld.
        /// </summary>
        public long SharesSldLong
        {
            get { return _sharesSldLong; }
            set
            {
                if (_sharesSldLong != value)
                {
                    _sharesSldLong = value;
                    RaisePropertyChanged("SharesSldLong");
                }
            }
        }
        
        /// <summary>
        /// Number of Shares sold short this is a component of nSharesSld.
        /// </summary>
        public long SharesSldShort
        {
            get { return _sharesSldShort; }
            set
            {
                if (_sharesSldShort != value)
                {
                    _sharesSldShort = value;
                    RaisePropertyChanged("SharesSldShort");
                }
            }
        }
        
        /// <summary>
        /// Buy side executions
        /// </summary>
        public long TicketsBot
        {
            get { return _ticketsBot; }
            set
            {
                if (_ticketsBot != value)
                {
                    _ticketsBot = value;
                    RaisePropertyChanged("TicketsBot");
                }
            }
        }
        
        /// <summary>
        /// Sell and Sell Short executions
        /// </summary>
        public long TicketsSld
        {
            get { return _ticketsSld; }
            set
            {
                if (_ticketsSld != value)
                {
                    _ticketsSld = value;
                    RaisePropertyChanged("TicketsSld");
                }
            }
        }
        
        /// <summary>
        /// Sell executions
        /// </summary>
        public long TicketsSldLong
        {
            get { return _ticketsSldLong; }
            set
            {
                if (_ticketsSldLong != value)
                {
                    _ticketsSldLong = value;
                    RaisePropertyChanged("TicketsSldLong");
                }
            }
        }
        
        /// <summary>
        /// Sell Short executions
        /// </summary>
        public long TicketsSldShort
        {
            get { return _ticketsSldShort; }
            set
            {
                if (_ticketsSldShort != value)
                {
                    _ticketsSldShort = value;
                    RaisePropertyChanged("TicketsSldShort");
                }
            }
        }


        
        /// <summary>
        /// Yesterday’s close
        /// </summary>
        public double ClosePrice
        {
            get { return _closePrice; }
            set
            {
                if (Math.Abs(_closePrice - value) > 0.000001)
                {
                    _closePrice = value;
                    RaisePropertyChanged("ClosePrice");
                }
            }
        }
        
        /// <summary>
        /// The total cost of BUY orders.
        /// </summary>
        public double DollarsBot
        {
            get { return _dollarsBot; }
            set
            {
                if (Math.Abs(_dollarsBot - value) > 0.000001)
                {
                    _dollarsBot = value;
                    RaisePropertyChanged("DollarsBot");
                }
            }
        }
        
        /// <summary>
        /// The total of fDollarsSldLong+ fDollarsSldShort
        /// </summary>
        public double DollarsSld
        {
            get { return _dollarsSld; }
            set
            {
                if (Math.Abs(_dollarsSld - value) > 0.000001)
                {
                    _dollarsSld = value;
                    RaisePropertyChanged("DollarsSld");
                }
            }
        }
        
        /// <summary>
        /// The total cost of SELL orders.
        /// </summary>
        public double DollarsSldLong
        {
            get { return _dollarsSldLong; }
            set
            {
                if (Math.Abs(_dollarsSldLong - value) > 0.000001)
                {
                    _dollarsSldLong = value;
                    RaisePropertyChanged("DollarsSldLong");
                }
            }
        }

        
        /// <summary>
        /// The total cost of SHRT orders.
        /// </summary>
        public double DollarsSldShort
        {
            get { return _dollarsSldShort; }
            set
            {
                if (Math.Abs(_dollarsSldShort - value) > 0.000001)
                {
                    _dollarsSldShort = value;
                    RaisePropertyChanged("DollarsSldShort");
                }
            }
        }
        
        /// <summary>
        /// The total of fDollarsBot+ fDollarsSld
        /// </summary>
        public double PositionCost
        {
            get { return _positionCost; }
            set
            {
                if (Math.Abs(_positionCost - value) > 0.000001)
                {
                    _positionCost = value;
                    RaisePropertyChanged("PositionCost");
                }
            }
        }
        
        /// <summary>
        /// This is the multiplier for options positions. This is for non-integer return values.
        /// </summary>
        public double PremiumMultiplier
        {
            get { return _premiumMultiplier; }
            set
            {
                if (Math.Abs(_premiumMultiplier - value) > 0.000001)
                {
                    _premiumMultiplier = value;
                    RaisePropertyChanged("PremiumMultiplier");
                }
            }
        }
        
        /// <summary>
        /// This is the Realized Profit/Loss value.
        /// </summary>
        public double Real
        {
            get { return _real; }
            set
            {
                if (Math.Abs(_real - value) > 0.000001)
                {
                    _real = value;
                    RaisePropertyChanged("Real");
                }
            }
        }


        
        /// <summary>
        /// Options field Number of underling shares per options contract
        /// </summary>
        public long SharesPerContract
        {
            get { return _sharesPerContract; }
            set
            {
                if (_sharesPerContract != value)
                {
                    _sharesPerContract = value;
                    RaisePropertyChanged("SharesPerContract");
                }
            }
        }
        
        /// <summary>
        /// This is the multiplier for options positions. For non-integers see fPremiumMultiplier.
        /// </summary>
        public long NPremiumMultiplier
        {
            get { return _nPremiumMultiplier; }
            set
            {
                if (_nPremiumMultiplier != value)
                {
                    _nPremiumMultiplier = value;
                    RaisePropertyChanged("NPremiumMultiplier");
                }
            }
        }


        
        /// <summary>
        /// Indicates this is the last of a list of events because of a request (GetCurrentPositions())
        /// </summary>
        public double Last
        {
            get { return _last; }
            set
            {
                if (_last != value)
                {
                    _last = value;
                    RaisePropertyChanged("Last");
                }
            }
        }

        
        /// <summary>
        /// Indicates that event is due to a request(GetCurrentPositions()) not a position change.
        /// </summary>
        public double MsgSnapShot
        {
            get { return _msgSnapShot; }
            set
            {
                if (_msgSnapShot != value)
                {
                    _msgSnapShot = value;
                    RaisePropertyChanged("MsgSnapShot");
                }
            }
        }
           
        #endregion

        #region event PropertyChangedEventHandler

        public event PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion
    }
}
